﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LPV_POS.mh_pos.mh_doanhthu
{
    public partial class frmbaocao_KetThuc_NgayLamViec : Form
    {
        string kho_hang_id = "";
        public frmbaocao_KetThuc_NgayLamViec(string _kho_hang_id)
        {
            InitializeComponent();
            kho_hang_id = _kho_hang_id;
        }

        private void frmbaocao_KetThuc_NgayLamViec_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            lblNgayLamViec.Text = Variable.ngay_lamviec.ToString("dd-MM-yyyy");

            DataSet ds = Get_Data(1, Variable.ngay_lamviec.ToString("yyyyMMdd"), Variable.ngay_lamviec.ToString("yyyyMMdd"), kho_hang_id, false);
            this.Show_Info(ds);
            this.Cursor = Cursors.Default;
        }

        private void btnDongY_Click(object sender, EventArgs e)
        {
            Variable.ngay_lamviec = Variable.ngay_lamviec.AddDays(1);

            int irt = new thuvien().SP_Update("sp_BH_CAU_HINH",
                                    new string[] { "@flag", "@NGAY_LAM_VIEC" },
                                    new object[] { 5, Variable.ngay_lamviec });

        }

        private void Show_Info(DataSet ds)
        {
            decimal iTHANHTIENTRUOC = 0;
            decimal iTHANHTIEN = 0;
            decimal iCHIECKHAU = 0;
            decimal iVat = 0;
            decimal iSERVICE_CHARGE = 0;
            decimal iPHUTHUKHAC = 0;
            decimal iKHUYENMAI = 0;
            decimal iTIENTIP = 0;
            decimal iTONGTHU = 0;
            decimal iTONGCHI = 0;
            decimal iCONGNO = 0;

            decimal.TryParse(ds.Tables[0].Rows[0]["THANHTIENTRUOC"] + "", out iTHANHTIENTRUOC);
            decimal.TryParse(ds.Tables[0].Rows[0]["THANHTIEN"] + "", out iTHANHTIEN);
            decimal.TryParse(ds.Tables[0].Rows[0]["CHIECKHAU"] + "", out iCHIECKHAU);

            decimal.TryParse(ds.Tables[0].Rows[0]["Vat"] + "", out iVat);
            decimal.TryParse(ds.Tables[0].Rows[0]["SERVICE_CHARGE"] + "", out iSERVICE_CHARGE);
            decimal.TryParse(ds.Tables[0].Rows[0]["PHUTHUKHAC"] + "", out iPHUTHUKHAC);
            decimal.TryParse(ds.Tables[0].Rows[0]["KHUYENMAI"] + "", out iKHUYENMAI);
            decimal.TryParse(ds.Tables[0].Rows[0]["TIENTIP"] + "", out iTIENTIP);
            decimal.TryParse(ds.Tables[0].Rows[0]["TONGTHU"] + "", out iTONGTHU);
            decimal.TryParse(ds.Tables[0].Rows[0]["TONGCHI"] + "", out iTONGCHI);
            decimal.TryParse(ds.Tables[0].Rows[0]["CONGNO"] + "", out iCONGNO);

            lbel_tongcongchuatanggiam.Text = iTHANHTIENTRUOC.ToString("N0");
            lbel_giamgia_1.Text = iCHIECKHAU.ToString("N0");
            lbel_tongcongdagiamgia.Text = (decimal.Parse(lbel_tongcongchuatanggiam.Text.Replace(",", "")) - decimal.Parse(lbel_giamgia_1.Text.Replace(",", ""))).ToString("N0");
            lbel_giamgia_2.Text = lbel_giamgia_1.Text;
            lbel_phuthu_2.Text = iPHUTHUKHAC.ToString("N0");
            lbel_vat_2.Text = iVat.ToString("N0");
            lbel_tienchi_2.Text = iTONGCHI.ToString("N0");
            lbel_tienthu_2.Text = iTONGTHU.ToString("N0");
            lbel_thuedichvu_2.Text = iSERVICE_CHARGE.ToString("N0");
            lbel_tientip_2.Text = iTIENTIP.ToString("N0");
            lbel_congno.Text = iCONGNO.ToString("N0");
            lbel_khuyenmai.Text = iKHUYENMAI.ToString("N0");

            decimal iCONGNO_ALL = 0;
            if (ds.Tables[0].Columns.Contains("CONGNO_ALL"))
                iCONGNO_ALL = decimal.Parse(ds.Tables[0].Rows[0]["CONGNO_ALL"] + "");
            else
                iCONGNO_ALL = iCONGNO;
            //string sab = (iTHANHTIENTRUOC
            //                                    - iCHIECKHAU
            //                                    + iVat
            //                                    + iSERVICE_CHARGE
            //                                    + iPHUTHUKHAC
            //                                    - iKHUYENMAI
            //                                    + iTIENTIP
            //                                    + iTONGTHU
            //                                    - iTONGCHI
            //                                    - iCONGNO
            //                                    ).ToString("N0");

            lbel_datanggiam.Text = (iTHANHTIEN
                                    + iTONGTHU
                                    - iTONGCHI//                                    + iPHUTHUKHAC
                                    - iCONGNO_ALL
                                    - iKHUYENMAI).ToString("N0");

            lbel_tientrongket.Text = lbel_datanggiam.Text;

        }

        private DataSet Get_Data(Int16 loaidoanhthu, string date_tungay, string date_denngay, string makho, Boolean loaibaocao)
        {
            thuvien tv = new thuvien();
            string[] s = new string[] { "@FLAG", "@FROMDATE", "@TODATE", "@MAKHOHANG", "@LOAIBAOCAO" };
            object[] o = new object[] { loaidoanhthu, date_tungay, date_denngay, makho, loaibaocao };
            DataSet ds = tv.SP_SelectDataset("sp_baocaodoanhthu_hanghoa", s, o);
            return ds;
        }
    }
}
